package com.peas.fastdfs.controller;


import com.peas.fastdfs.entity.QuartzJob;
import com.peas.fastdfs.quartz.TestQuartzTask3;
import com.peas.fastdfs.service.QuartzManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * from  https://blog.csdn.net/luo201227/article/details/46826581
 */
@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    private QuartzManagerService quartzManagerService;


    @GetMapping
    public String test(){
        QuartzJob quartzJob = new QuartzJob();
        quartzJob.setJobId(UUID.randomUUID().toString());
        quartzJob.setJobName("test-init");
        quartzJob.setJobGroup("test-group");
        quartzJob.setJobStatus(1);
        quartzJob.setCronExpression("0/3 * * * * ?");
        Map<String, Object> map = new HashMap<>();
        map.put("id",UUID.randomUUID().toString());
        quartzJob.setJobDataMap(map);
        quartzManagerService.initJob(quartzJob, TestQuartzTask3.class);
        return "ok";
    }

    @DeleteMapping
    public String test2(){
        QuartzJob quartzJob = new QuartzJob();
        quartzJob.setJobName("test-init");
        quartzJob.setJobGroup("test-group");
        quartzManagerService.deleteJob(quartzJob);
        return "ok";
    }

}
